package com.tanjor.main.sys.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tanjor.common.util.ConstantUtil;
import com.tanjor.sys.dubbo.dto.SysRoleDTO;
import com.tanjor.user.dubbo.dto.SysUserDTO;
import com.tanjor.user.dubbo.impl.interfaces.ISysUserDubbo;
@Controller
@RequestMapping("/sys")
public class LoginController {
	
	@Autowired
	private ISysUserDubbo sysUserDubbo;
	
	@RequestMapping("/login")
	@ResponseBody
	public Map<String,Object> login(HttpServletRequest request,String userNo,String password){
		Map<String,Object> map = sysUserDubbo.login(userNo, password);
		SysUserDTO userDTO = (SysUserDTO) map.get("sysuser");
		SysRoleDTO sysRoleDTO = (SysRoleDTO) map.get("sysrole");
		request.getSession().setAttribute(ConstantUtil.SESSION.SYS_SESSION_USER,userDTO);  
		request.getSession().setAttribute(ConstantUtil.SESSION.SYS_SESSION_ROLE,sysRoleDTO);  
		map.put("sysuser", null);
		map.put("sysrole", null);
		return map;
	}
	
	@RequestMapping("/loginOut")
	@ResponseBody
	public String loginOut(HttpServletRequest request){
		request.getSession(true).invalidate();  
		return "";
	}
}
